<?php $this->load->view('includes/head.php'); ?>
<div class="container">
  <div class="row">
    <div class="col-sm-12">
      <h3>My Tasks </h3>
      <hr>
      <?php if (!$tasks || count($tasks) < 1): ?>
      <div class="alert alert-dismissable alert-warning" role="alert">
        <p>There are no tasks currently assigned to you.</p>
      </div>
      <?php else: ?>
      <table class="table table-hover">
        <thead>
          <tr>
            <th>#</th>
            <th>Date Created</th>
            <th>Task</th>
            <th>Role(s)</th>
            <th>Due Date</th>
            <th>Action</th>
          </tr>
        </thead>
        <tbody>
          <?php
          $count = 0;
          foreach ($tasks as $task) {
          $title = $task->title;
          $view_task_url = site_url('tasks/'.$task->url);
          $delete_task_url = site_url('tasks/delete/'.$task->url);
          $edit_task_url = site_url('tasks/edit/'.$task->url);
          $content = $task->content;
          $count++;
          date_default_timezone_set('GMT');
          $due_date = mdate('%M %d, %Y',strtotime($task->date_due));
          $date_created = mdate('%M %d, %Y',  strtotime($task->date_created));
          $action;
          $id = $task->user_id;
          $responsible = json_decode($task->responsible);
          $accountable = json_decode($task->accountable);
          $consulted = json_decode($task->consulted);
          $informed = json_decode($task->informed);

          if ($userid == $task->user_id) {
            $action = '<li><a href="'.$delete_task_url.'" rel="tooltip" class="btn btn-danger btn-xs" data-toggle="tooltip" data-placement="right" title="Delete Task"><i class="fa fa-times"></i></a></li>';
          }else{
            $action = '';
          }
          echo<<<TOP
          <tr>
            <td>$count</td>
            <td>$date_created</td>
            <td class="edit-row">$title</td>
            
TOP;


          
          echo '<td class="table-roles">';
              echo (is_array($responsible) && in_array($id, $responsible)) ? '<em><span class="levels">Responsible</span></em> ' : '';
              echo (is_array($accountable) && in_array($id, $accountable)) ? '<em><span class="levels">Accountable</span></em> ' : '';
              echo (is_array($consulted) && in_array($id, $consulted)) ? '<em><span class="levels">Consulted</span></em> ' : '';
              echo (is_array($informed) && in_array($id, $informed)) ? '<em><span class="levels">Informed</span></em> ' : '';
          echo '</td>';

            echo<<<BTM
            <td>$due_date</td>
            <td>
              <div class="btn-group">
                <ul class="list-inline">
                  <li>
                    <a href="$view_task_url" rel="tooltip" class="btn btn-primary btn-xs" data-toggle="tooltip" data-placement="left" title="View Task"><i class="fa fa-eye"></i></a>
                  </li>
                  <li>
                    <a href="$edit_task_url" rel="tooltip" class="btn btn-success btn-xs" data-toggle="tooltip" data-placement="top" title="Edit Task"><i class="fa fa-pencil"></i></a>
                  </li>
                  $action
                </ul>
              </div>
            </td>
          </tr>
BTM;
          }
          ?>
        </tbody>
      </table>
      <?php endif; ?>
    </div> <?php // Close Column 12 ?>
    


 

  </div>
</div>
